<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Java 字节码反编译成汇编-使用JITWatch | Finen&#39;s Blog</title>
    <meta name="generator" content="VuePress 1.4.1">
    <link rel="icon" href="/logo.png">
    <link rel="manifest" href="/manifest.json">
    <link rel="apple-touch-icon" href="/icons/apple-touch-icon-152x152.png">
    <link rel="mask-icon" href="/icons/safari-pinned-tab.svg" color="#3eaf7c">
    <meta name="description" content="Stay Hungry! Stay Foolish!">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
    <meta name="msapplication-TileColor" content="#000000">
    <link rel="preload" href="/assets/css/0.styles.331bc503.css" as="style"><link rel="preload" href="/assets/js/app.8657dc36.js" as="script"><link rel="preload" href="/assets/js/3.655fda8f.js" as="script"><link rel="preload" href="/assets/js/22.73d5a697.js" as="script"><link rel="preload" href="/assets/js/11.32858d9c.js" as="script"><link rel="prefetch" href="/assets/js/1.af5e15a9.js"><link rel="prefetch" href="/assets/js/10.3d57a2e0.js"><link rel="prefetch" href="/assets/js/12.cef9d203.js"><link rel="prefetch" href="/assets/js/13.02beb1f0.js"><link rel="prefetch" href="/assets/js/14.7efc03c9.js"><link rel="prefetch" href="/assets/js/15.6bbbab3f.js"><link rel="prefetch" href="/assets/js/16.f90edb71.js"><link rel="prefetch" href="/assets/js/17.0d4d6c13.js"><link rel="prefetch" href="/assets/js/18.76dd8979.js"><link rel="prefetch" href="/assets/js/19.7da82e6f.js"><link rel="prefetch" href="/assets/js/20.55ee1642.js"><link rel="prefetch" href="/assets/js/21.088a02d1.js"><link rel="prefetch" href="/assets/js/23.829e24c3.js"><link rel="prefetch" href="/assets/js/24.2f258433.js"><link rel="prefetch" href="/assets/js/25.0a52df22.js"><link rel="prefetch" href="/assets/js/26.1c66cc2f.js"><link rel="prefetch" href="/assets/js/27.aa781144.js"><link rel="prefetch" href="/assets/js/28.b2cf7947.js"><link rel="prefetch" href="/assets/js/29.b61b1598.js"><link rel="prefetch" href="/assets/js/30.ba0ae8b1.js"><link rel="prefetch" href="/assets/js/31.7637d043.js"><link rel="prefetch" href="/assets/js/32.e552a016.js"><link rel="prefetch" href="/assets/js/33.334376b0.js"><link rel="prefetch" href="/assets/js/34.08c95f99.js"><link rel="prefetch" href="/assets/js/35.76b6b95d.js"><link rel="prefetch" href="/assets/js/36.539b6d80.js"><link rel="prefetch" href="/assets/js/37.850783a5.js"><link rel="prefetch" href="/assets/js/38.06c33708.js"><link rel="prefetch" href="/assets/js/39.85fc61d5.js"><link rel="prefetch" href="/assets/js/4.12c21fd1.js"><link rel="prefetch" href="/assets/js/40.cdc93796.js"><link rel="prefetch" href="/assets/js/41.be79357e.js"><link rel="prefetch" href="/assets/js/42.e1ea76e5.js"><link rel="prefetch" href="/assets/js/43.06bf748b.js"><link rel="prefetch" href="/assets/js/44.ebd514b5.js"><link rel="prefetch" href="/assets/js/45.12908515.js"><link rel="prefetch" href="/assets/js/46.78fb0130.js"><link rel="prefetch" href="/assets/js/47.1a3b6cfd.js"><link rel="prefetch" href="/assets/js/48.ef04cdb5.js"><link rel="prefetch" href="/assets/js/49.763fd944.js"><link rel="prefetch" href="/assets/js/5.e50a6b6f.js"><link rel="prefetch" href="/assets/js/50.c8a7a24d.js"><link rel="prefetch" href="/assets/js/51.aaa9e6c7.js"><link rel="prefetch" href="/assets/js/52.7d3a85df.js"><link rel="prefetch" href="/assets/js/53.00784a7d.js"><link rel="prefetch" href="/assets/js/54.bd3845dd.js"><link rel="prefetch" href="/assets/js/55.10a67e4b.js"><link rel="prefetch" href="/assets/js/56.eb909b5a.js"><link rel="prefetch" href="/assets/js/57.4b821666.js"><link rel="prefetch" href="/assets/js/58.1db8af1f.js"><link rel="prefetch" href="/assets/js/59.d3045373.js"><link rel="prefetch" href="/assets/js/6.f25d4964.js"><link rel="prefetch" href="/assets/js/60.e1ccc619.js"><link rel="prefetch" href="/assets/js/61.eca4de24.js"><link rel="prefetch" href="/assets/js/62.be7238a5.js"><link rel="prefetch" href="/assets/js/63.a6ace044.js"><link rel="prefetch" href="/assets/js/64.bbd88e61.js"><link rel="prefetch" href="/assets/js/65.1f6c1848.js"><link rel="prefetch" href="/assets/js/66.d22e96e8.js"><link rel="prefetch" href="/assets/js/67.80ad6427.js"><link rel="prefetch" href="/assets/js/68.130aa1f6.js"><link rel="prefetch" href="/assets/js/69.4b778299.js"><link rel="prefetch" href="/assets/js/7.9c54e368.js"><link rel="prefetch" href="/assets/js/70.edcac904.js"><link rel="prefetch" href="/assets/js/71.90aa842c.js"><link rel="prefetch" href="/assets/js/72.4cb8aeae.js"><link rel="prefetch" href="/assets/js/73.6f272f7b.js"><link rel="prefetch" href="/assets/js/74.d36a7a16.js"><link rel="prefetch" href="/assets/js/75.362400fa.js"><link rel="prefetch" href="/assets/js/76.140673a6.js"><link rel="prefetch" href="/assets/js/77.5f1336bf.js"><link rel="prefetch" href="/assets/js/78.6105e050.js"><link rel="prefetch" href="/assets/js/79.dd680c04.js"><link rel="prefetch" href="/assets/js/8.786d8198.js"><link rel="prefetch" href="/assets/js/80.ebfb944f.js"><link rel="prefetch" href="/assets/js/81.892d344c.js"><link rel="prefetch" href="/assets/js/9.b0b77105.js">
    <link rel="stylesheet" href="/assets/css/0.styles.331bc503.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">Finen's Blog</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/post/" class="nav-link">
  文章
</a></div><div class="nav-item"><a href="/archives/" class="nav-link">
  归档
</a></div><div class="nav-item"><a href="/tags/" class="nav-link">
  标签云
</a></div><div class="nav-item"><a href="/friends/" class="nav-link">
  友人帐
</a></div> <a href="https://github.com/hirCodd" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/post/" class="nav-link">
  文章
</a></div><div class="nav-item"><a href="/archives/" class="nav-link">
  归档
</a></div><div class="nav-item"><a href="/tags/" class="nav-link">
  标签云
</a></div><div class="nav-item"><a href="/friends/" class="nav-link">
  友人帐
</a></div> <a href="https://github.com/hirCodd" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <!----> </aside> <main class="page"> <div class="title-content"><div class="el-card box-cards is-never-shadow"><!----><div class="el-card__body"><h2>Java 字节码反编译成汇编-使用JITWatch</h2> <div class="page-info"><i aria-hidden="true" class="el-icon-s-custom"></i> <span class="i-text">Finen</span> <i aria-hidden="true" class="el-icon-collection-tag"><span class="i-text">JavaTool</span></i> <i aria-hidden="true" class="el-icon-time"></i> <span class="i-text">2021-04-16</span> <span id="/blog/java/java-jitwatch.html" data-flag-title="Java 字节码反编译成汇编-使用JITWatch" class="leancloud-visitors"><i aria-hidden="true" class="el-icon-view"></i> <i class="leancloud-visitors-count">1000000</i></span></div></div></div></div> <div class="theme-default-content content__default"><h1 id="java-字节码反编译成汇编"><a href="#java-字节码反编译成汇编" class="header-anchor">#</a> Java 字节码反编译成汇编</h1> <blockquote><p>本位以windows环境为前提，JDK版本为Oracle Sun JDK8-64位</p></blockquote> <h2 id="hsdis环境准备"><a href="#hsdis环境准备" class="header-anchor">#</a> Hsdis环境准备</h2> <h3 id="_1-下载hsdis-amd64-dylib"><a href="#_1-下载hsdis-amd64-dylib" class="header-anchor">#</a> 1.下载hsdis-amd64.dylib</h3> <blockquote><p>下载地址如下：https://github.com/evolvedmicrobe/benchmarks/blob/master/hsdis-amd64.dylib</p></blockquote> <h3 id="_2-下载hsdis-amd64-dll"><a href="#_2-下载hsdis-amd64-dll" class="header-anchor">#</a> 2.下载hsdis-amd64.dll</h3> <blockquote><p>下载地址如下：https://github.com/atzhangsan/file_loaded</p></blockquote> <h3 id="_3-配置hsdis-amd64-dylib和hsdis-amd64-dll"><a href="#_3-配置hsdis-amd64-dylib和hsdis-amd64-dll" class="header-anchor">#</a> 3.配置hsdis-amd64.dylib和hsdis-amd64.dll</h3> <p>a.将下载好的hsdis-amd64.dll文件放置在JDK路径下<code>\jre\bin</code>目录下。</p> <blockquote><p>e.g. C:\Program Files\Java\jdk1.8.0_161\jre\bin</p></blockquote> <p>b.将下载好的hsdis-amd64.dylib文件放置在JDK路径下的<code>\jre\lib</code>目录下。</p> <blockquote><p>e.g. C:\Program Files\Java\jdk1.8.0_161\jre\lib</p></blockquote> <h3 id="_4-测试验证是否配置成功"><a href="#_4-测试验证是否配置成功" class="header-anchor">#</a> 4.测试验证是否配置成功</h3> <p>使用命令<code>java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -version</code>验证是否配置成功。如果出现如下所示则说明配置成功。</p> <p><img src="https://gitee.com/forge-logic/images-lib/raw/master/img/image-20210414230849483.png" alt="image-20210414230849483"></p> <h3 id="_5-自行构建hsdis-如果你有兴趣的话"><a href="#_5-自行构建hsdis-如果你有兴趣的话" class="header-anchor">#</a> 5.自行构建hsdis(如果你有兴趣的话)</h3> <p>如果你有兴趣自行编译hsdis的话，可以参考如下的几个链接，然后把编译好的文件放在jdk的jre目录下的如上所<code>3</code>述路径。</p> <p>1.http://www.chrisnewland.com/building-hsdis-on-linux-amd64-on-debian-369</p> <p>2.http://psy-lob-saw.blogspot.com/2013/01/java-print-assembly.html</p> <h2 id="jitwatch环境"><a href="#jitwatch环境" class="header-anchor">#</a> JITWatch环境</h2> <h3 id="_1-下载jitwatch"><a href="#_1-下载jitwatch" class="header-anchor">#</a> 1.下载JITWatch</h3> <blockquote><p>下载路径如下：https://github.com/AdoptOpenJDK/jitwatch/releases</p></blockquote> <p>如果你有兴趣的话，当然也可以参考官方文档进行编译。</p> <p>JITWatch链接如下：</p> <blockquote><p>https://github.com/AdoptOpenJDK/jitwatch</p></blockquote> <p>编译命令如下：</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>ant编译：
ant clean compile <span class="token builtin class-name">test</span> run
maven编译：
mvn clean compile <span class="token builtin class-name">test</span> exec:java
gradle编译：
gradlew clean build run
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="_2-配置运行jitwatch"><a href="#_2-配置运行jitwatch" class="header-anchor">#</a> 2.配置运行JITWatch</h3> <p>a.启动，使用<code>java -jar jitwatch-ui-1.4.0-shaded-win.jar</code>启动jitwatch，启动成功后如下所示</p> <p><img src="https://gitee.com/forge-logic/images-lib/raw/master/img/image-20210414232505669.png" alt="image-20210414232505669"></p> <p>b.配置，点击<code>sandbox</code>按钮打开窗口，再点击<code>Configure Sandbox</code>按钮，配置如下几个参数</p> <blockquote><p>1.java classes目录</p> <p>2.java 运行目录为你本地的配置使用的JDK路径</p> <p>3.java运行参数，添加hsdis的运行参数配置</p></blockquote> <p><img src="https://gitee.com/forge-logic/images-lib/raw/master/img/image-20210414233652204.png" alt="image-20210414233652204"></p> <p>c.运行，点击<code>open</code>按钮打开需要编译的java代码，点击<code>Run</code>按钮运行得到下图所示</p> <p><img src="https://gitee.com/forge-logic/images-lib/raw/master/img/image-20210414232726380.png" alt="image-20210414232726380"></p> <p><img src="https://gitee.com/forge-logic/images-lib/raw/master/img/image-20210414234418226.png" alt="image-20210414234418226"></p> <h3 id="_3-jitwatch简单使用"><a href="#_3-jitwatch简单使用" class="header-anchor">#</a> 3.JITwatch简单使用</h3> <h4 id="模块化查看字节码和汇编码"><a href="#模块化查看字节码和汇编码" class="header-anchor">#</a> 模块化查看字节码和汇编码</h4> <p><img src="https://gitee.com/forge-logic/images-lib/raw/master/img/image-20210414234700267.png" alt="image-20210414234700267"></p> <h4 id="使用toplist查看资源占用率"><a href="#使用toplist查看资源占用率" class="header-anchor">#</a> 使用topList查看资源占用率</h4> <p>在JITWatch窗口点击<code>TopList</code>按钮，即可查看资源占用率。</p> <p><img src="https://gitee.com/forge-logic/images-lib/raw/master/img/image-20210414235239556.png" alt="image-20210414235239556"></p> <h4 id="更多资料"><a href="#更多资料" class="header-anchor">#</a> 更多资料</h4> <p>1.https://www.chrisnewland.com/images/jitwatch/HotSpot_Profiling_Using_JITWatch.pdf</p> <p>2.https://github.com/AdoptOpenJDK/jitwatch/wiki</p> <h2 id="参考文章"><a href="#参考文章" class="header-anchor">#</a> 参考文章</h2> <p>1.利用hsdis和JITWatch查看分析HotSpot JIT compiler生成的汇编代码.https://blog.csdn.net/hengyunabc/article/details/26898657</p> <p>2.JITWatch Wiki.https://github.com/AdoptOpenJDK/jitwatch/wiki</p> <blockquote><p>我的博客即将同步至腾讯云+社区，邀请大家一同入驻：https://cloud.tencent.com/developer/support-plan?invite_code=17nuh698omdi4</p></blockquote></div> <footer class="page-edit"><!----> <!----></footer> <!---->  <div class="vcomment"><div id="vcomments"></div></div></main></div><div class="global-ui"><!----><!----></div></div>
    <script src="/assets/js/app.8657dc36.js" defer></script><script src="/assets/js/3.655fda8f.js" defer></script><script src="/assets/js/22.73d5a697.js" defer></script><script src="/assets/js/11.32858d9c.js" defer></script>
  </body>
</html>
